#include "optionswidget.h"
#include "filetable.h"
#include "slepui.h"


/*

	if(method == Method_Least_R || method == Method_nnLeast_R || method == Method_Least_C || method == Method_nnLeast_C
		|| method == Method_Logistic_R || method == Method_nnLogistic_R || method == Method_Logistic_C || method == Method_nnLogistic_C
		|| method == Method_glLeast_R || method == Method_glLogistic_R
		|| method == Method_mtLeast_R || method == Method_mtLeast_C
		|| method == Method_mcLeast_R || method == Method_mcLeast_C
		|| method == Method_mtLogistic_R|| method == Method_mtLogistic_C
		|| method == Method_mcLogistic_R || method == Method_mcLogistic_C)
*/

void OptionsWidget::createStartOptions(){
	/* Create a vertical box layout and add all the separate widgets to it */
    QLayout *layout = new QVBoxLayout(this);

	/* the main widget here is the Start tab - so create a widget for it */ 
    QWidget *startOptionsWidget = new QWidget(this);

	/* set the layout as the vertical box layout */
    startOptionsWidget->setLayout(layout);

	/* now add the tab with a name to it */
    tabWidget->addTab(startOptionsWidget,tr("Start Options"));

	/* First set of options for this is the groupbox containing 'init' */
    startOptions = new QGroupBox(tr("Start options"), this);

	/* In a grid layout add the label for 'init', followed by the 'init' values as radio buttons with definitions */
    QGridLayout *gstartLayout = new QGridLayout;
    buttonGroupInit = new QButtonGroup(this);
    labelInit = new QLabel(tr("Starting point"));
    buttonGroupInit->addButton(new QRadioButton(tr("x0 - set automatically")),0);
    buttonGroupInit->addButton(new QRadioButton(tr("x0 and other starting points specified")),1);
    buttonGroupInit->addButton(new QRadioButton(tr("x0 = zeroes")),2);

	/* only one button can be selected and set it to init=2 */
    buttonGroupInit->setExclusive(true);
    (buttonGroupInit->button(2))->setChecked(true);
    opts->init = 2;

	/* now add the widgets to the grid layout*/
    gstartLayout->addWidget(labelInit,0,0,3,1,Qt::AlignTop | Qt::AlignLeft);
    gstartLayout->addWidget(buttonGroupInit->button(0),0,1, Qt::AlignLeft);
    gstartLayout->addWidget(buttonGroupInit->button(1),1,1, Qt::AlignLeft);
    gstartLayout->addWidget(buttonGroupInit->button(2),2,1, Qt::AlignLeft);

	/* set the layout to the group box */
    startOptions->setLayout(gstartLayout);

	/* add it to the main widget */
    layout->addWidget(startOptions);

	/* If this is method with just x0 as vector just add x0 alone */
	if( method == Method_Least_R || method == Method_nnLeast_R || method == Method_Least_C 
		|| method == Method_nnLeast_C || method == Method_glLeast_R 
		|| method == Method_Logistic_R || method == Method_nnLogistic_R || method == Method_Logistic_C 
		|| method == Method_nnLogistic_C  || method == Method_glLogistic_R){

			x0NormOption = new QGroupBox(tr("x0"), this);
			x0NormOption->setLayout(new QGridLayout);
			tablex0 = new FileTable(this);
			x0NormOption->layout()->addWidget(tablex0);
			layout->addWidget(x0NormOption);
			connect(tablex0,SIGNAL(signalSelectionChanged(void*)),this,SLOT(setOPTS_x0(void*)));
			connect(buttonGroupInit->button(1),SIGNAL(toggled(bool)),x0NormOption,SLOT(setEnabled(bool)));
			x0NormOption->setEnabled(false);
	}

	/* if it is logistic then add c0, only if it is a single value */
	if(	method == Method_Logistic_R || method == Method_nnLogistic_R || method == Method_Logistic_C 
		|| method == Method_nnLogistic_C  || method == Method_glLogistic_R){

			c0NormOption = new QGroupBox(tr("c0"), this);
			c0NormOption->setLayout(new QGridLayout);
			QDoubleSpinBox *c0SpinBox = new QDoubleSpinBox(this);
			c0SpinBox->setRange(0.0,100.0);
			c0SpinBox->setDecimals(3);
			c0SpinBox->setSingleStep(0.001);
			c0NormOption->layout()->addWidget(c0SpinBox);
			layout->addWidget(c0NormOption);
			connect(buttonGroupInit->button(1),SIGNAL(toggled(bool)),c0NormOption,SLOT(setEnabled(bool)));
			c0NormOption->setEnabled(false);
			connect(c0SpinBox,SIGNAL(valueChanged(double)),this,SLOT(setOPTS_c0(double)));
	}
	
	/* for multi-task and multi-class X0 is a matrix */
	if( method == Method_mtLeast_R || method == Method_mtLeast_C 
		|| method == Method_mcLeast_R || method == Method_mcLeast_C		
		|| method == Method_mtLogistic_R|| method == Method_mtLogistic_C
		|| method == Method_mcLogistic_R || method == Method_mcLogistic_C){

			x0NormOption = new QGroupBox(tr("X0"), this);
			x0NormOption->setLayout(new QGridLayout);
			tablex0 = new FileTable(this);
			x0NormOption->layout()->addWidget(tablex0);
			layout->addWidget(x0NormOption);

			connect(tablex0,SIGNAL(signalSelectionChanged(void*)),this,SLOT(setOPTS_X0(void*)));

			connect(buttonGroupInit->button(1),SIGNAL(toggled(bool)),x0NormOption,SLOT(setEnabled(bool)));
			x0NormOption->setEnabled(false);
	}


	/* for multi-class or multitask logistic c0 is a vector */
	if( method == Method_mtLogistic_R || method == Method_mtLogistic_C
		|| method == Method_mcLogistic_R || method == Method_mcLogistic_C){
			c0NormOption = new QGroupBox(tr("c0(vector)"), this);
			c0NormOption->setLayout(new QGridLayout);
			tablec0 = new FileTable(this);
			c0NormOption->layout()->addWidget(tablec0);
			layout->addWidget(c0NormOption);

			connect(tablec0,SIGNAL(signalSelectionChanged(void*)),this,SLOT(setOPTS_c0_v(void*)));
			connect(buttonGroupInit->button(1),SIGNAL(toggled(bool)),c0NormOption,SLOT(setEnabled(bool)));
			c0NormOption->setEnabled(false);
	}

	/* stretch the remaining as space */
    ((QBoxLayout*)layout)->addStretch();

}